package com.android.clinic.app.ui.widget.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;

import com.android.clinic.app.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by cheng on 2018/3/13.
 */
public class DiagnosedDialog {

    private Context mContext;
    private Dialog mDialog;

    private List<String> listDay = new ArrayList<>();
    private List<CheckBox> checkBoxList = new ArrayList<>();
    private int radioSize = 0;
    private OnCompleteClickListener onCompleteClickListener;

    public void setOnCompleteClickListener(OnCompleteClickListener onCompleteClickListener) {
        this.onCompleteClickListener = onCompleteClickListener;
    }

    public DiagnosedDialog(Context context) {
        this.mContext = context;
        init();
    }

    private void init() {
        mDialog = new Dialog(mContext, R.style.custom_dialog);
        View convertView = LayoutInflater.from(mContext).inflate(R.layout.dialog_diagnosed_layout, null);
        CheckBox cbAm = (CheckBox) convertView.findViewById(R.id.radio_am);
        CheckBox cbPm = (CheckBox) convertView.findViewById(R.id.radio_pm);
        CheckBox cbNight = (CheckBox) convertView.findViewById(R.id.radio_night);
        Button btnReservation = (Button) convertView.findViewById(R.id.btn_reservation);
        mDialog.setContentView(convertView);

        checkBoxList.add(cbAm);
        checkBoxList.add(cbPm);
        checkBoxList.add(cbNight);
        radioSize = checkBoxList.size();

        btnReservation.setOnClickListener(v -> {
           for (int i = 0; i < radioSize; i++) {
               if (checkBoxList.get(i).isChecked()) {
                   listDay.add(checkBoxList.get(i).getTag().toString());
               }
           }
           if (null != onCompleteClickListener) {
               onCompleteClickListener.onComplete(listDay);
           }
           dismiss();
        });
    }

    public void setRadioButtonCheckStatus(List<String> list) {
        for (int i = 0; i < radioSize; i++) {
            for (int j = 0 ; j < list.size(); j++) {
                checkBoxList.get(i).setEnabled(false);
                if (checkBoxList.get(i).getTag().equals(list.get(j))) {
                    checkBoxList.get(i).setChecked(true);
                }
            }
        }
    }

    public void show() {
        mDialog.show();
    }
    public void dismiss() {
        mDialog.dismiss();
    }

    public interface OnCompleteClickListener {
        void onComplete(List<String> listDay);
    }


}
